<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>华夏会计网在线考试系统</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <base href="http://localhost:8888" />

</head>
<body>

<div id="layout"></div>

<script>
    window.ondragover=function(e) { e.preventDefault(); return false };
    window.ondrop=function(e) { e.preventDefault(); return false };
    document.body.onselectstart = function () {
        return false;
    };
</script>

<script src="./public/lokiApi.js"></script>
<script>
//const lokiApi = require('public/lokiApi.js');
const jsonfile = require('jsonfile');
const XLSX = require('xlsx');
const ip = require('ip');
const cwd = process.cwd();
const clipboard = nw.Clipboard.get();

const SessionModel = lokiApi('./dba/session.json');
const AdminModel = lokiApi('./dba/admin.json');
const ExamModel = lokiApi('./dba/exam.json');
const RoomModel = lokiApi('./dba/room.json');

const fs = require('fs');
const json2xls = require('json2xls');
function saveXls(json,filename) {
    var xls = json2xls(json);
    var filepath = './dba/export/'+filename+'.xlsx';
    fs.writeFileSync(filepath, xls, 'binary');
    document.getElementById('download').href = filepath;
    document.getElementById('download').click();
}

//激活浏览器,打开url
function openBrowser(uri){
    nw.Shell.openExternal(uri);
}

/**
 * 启动server服务
 * @type {API}
 */
const pm2 = require('pm2');
const Server = {
    start : function (callback) {
        pm2.connect(function(err) {
            if (err) {
                console.error(err);
                process.exit(2);
            }

//            pm2.start({
//                name : 'exam',
//                script    : './bin/www',         // Script to be run
//                exec_mode : 'cluster',        // Allows your app to be clustered
//                instances : 4,                // Optional: Scales your app by 4
//                max_memory_restart : '100M'   // Optional: Restarts your app if it reaches 100Mo
//            }, function(err, apps) {
//                pm2.disconnect();   // Disconnects from PM2
//                if (err) throw err
//                callback && typeof callback === 'function' && callback();
//            });

            pm2.start({
                name : 'exam',
                script    : './bin/www'
            }, function(err, apps) {
                pm2.disconnect();   // Disconnects from PM2
                if (err) throw err
                callback && typeof callback === 'function' && callback();
            });
        });
    },
    stop : function (callback) {
        pm2.connect(function(err) {
            if (err) {
                console.error(err);
                process.exit(2);
            }
            pm2.stop('exam',function (err) {
                if (err) throw err
                callback && typeof callback === 'function' && callback();
            })
        });
    }
}

//function addDom(type,link) {
//    if(type == 'script'){
//        var dom = document.createElement('script');
//        dom.src = './public/dist/'+link;
//        document.body.appendChild(dom);
//    }else{
//        var dom = document.createElement('link');
//        dom.rel = "stylesheet";
//        dom.type = "text/css";
//        dom.href = './public/dist/'+link;
//        document.getElementsByTagName('head')[0].appendChild(dom);
//    }
//}
//
//fs.readFile("./public/dist/mapping.json",'utf8',function (err,doc) {
//    var doc = JSON.parse(doc);
//    addDom('link',doc['panel.css']);
//    addDom('script',doc['vendor.js']);
//    addDom('script',doc['panel.js']);
//});
</script>

<script src="http://localhost:8888/public/dll/vendor.dll.js"></script>
<script src="http://localhost:8888/dist/panel.bundle.js"></script>

<a href="" download style="display: none;" id="download">download</a>
</body>
</html>